package com.example.video.adapter

import android.widget.ImageView
import android.widget.MediaController
import android.widget.VideoView
import com.blankj.utilcode.util.ToastUtils
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.VideoEntity
import com.example.video.R
import com.example.video.room.AppDBUtils

class VideoAdapter:BaseQuickAdapter<VideoEntity,BaseViewHolder>(R.layout.item_video){
    override fun convert(holder: BaseViewHolder, item: VideoEntity) {
        holder.setText(R.id.video_tv,item.title)
        //Glide.with(context).load(item.videomainimag).into(holder.getView(R.id.video_iv))
        //查询数据库中是否存在
        val list = AppDBUtils.getDb().getStarDao().queryById(item.id)
        //存在，证明已经收藏了，点击将执行取消收藏功能
        if(list.size>0){
           holder.getView<ImageView>(R.id.video_star).setImageResource(R.drawable.ic_star_yes)
        }else{
            holder.getView<ImageView>(R.id.video_star).setImageResource(R.drawable.ic_star)
        }
        val videoView = holder.getView<VideoView>(R.id.vv)
        videoView.setVideoPath(item.videopath)
        videoView.setMediaController(MediaController(context))
        videoView.start()

    }
}